# -*- coding: utf-8 -*-
# @Time   :2022/8/16 20:08
# @Author :jk
# @File   :conftest.py

import requests
import pytest
import json

@pytest.fixture(scope="session")
def get_token_fixture():
       '''
       登录->获取token
       作用域session的Fixture函数，返回token
       :return:
       '''
       headers = {"Content-Type":"application/json;charset=utf8"}
       url = "http://litemall.hogwarts.ceshiren.com/wx/auth/login"
       _data ={
           "username":"user123",
           "password":"user123"
       }
       res = requests.post(url=url,headers=headers,json=_data).text
       res = json.loads(res)
       # print(res)
       token = res["data"]["token"]
       return token
@pytest.fixture()
def get_goods_list(get_token_fixture):
    '''
    查询商品信息(需要先登录)
    :param get_token_fixture:
    :return:
    '''
    #通过Fixture函数获取get_token_fixture值，即token，再将token添加到请求头中
    headers = {"Content-Type": "application/json;charset=utf8",
               "token":get_token_fixture}
    url = "http://litemall.hogwarts.ceshiren.com/wx/goods/list"
    params = {
        "keyword":"",
        "page":1,
        "limit":10
    }
    res = requests.get(url=url,headers=headers,params=params).text
    res = json.loads(res)
    id = res["data"]["list"][0]["id"]
    proId = res["data"]["filterCategoryList"][0]["pid"]
    print(res)
    print(id, proId)
    return id,proId
    # assert res["errno"] == 0



